package com.felix.thread;

/**
 * SynchronizedDemo
 *
 * @author xuejinhua
 * @date 2018/10/12 14:08
 */
public class SynchronizedDemo implements Runnable {

    private static int count = 0;

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(new SynchronizedDemo()).start();
        }
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("result: " + count);
    }


    @Override
    public void run() {
        synchronized (SynchronizedDemo.class){
            for (int i = 0; i < 100000; i++) {
                count++;
            }
        }
    }
}
